import threading
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests


# print(threading, dir(threading))
#
# def t1_main(*args):
#     while True:
#         time.sleep(1)
#         print(f"线程t1 {args}")
#
#
# def t2_main(*args):
#     while True:
#         time.sleep(1)
#         print(f"线程t2 {args}")
#
#
# def main(*args):
#     print(f"主线程入口函数 {args}")
#
#     # 创建一个线程  并且指明 入口函数
#     t1 = threading.Thread(target=t1_main, args=("t1", "t11", "t111"))
#     t1.start()
#
#     t2 = threading.Thread(target=t2_main, args=("t2", "t22", "t222"))
#     t2.start()
#
#     while True:
#         time.sleep(1)
#         print(f"主线程")
#
#
# if __name__ == '__main__':
#     import sys
#     main(sys.argv[1:])


# # 请求列表 内存在主线程中
# # 每一个子线程都是用主线程的资源
# urls = [f"https://16.push2.eastmoney.com/api/qt/clist/get?pn={pn}&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_={int(time.time()*1000)}" for pn in range(1, 282)]
#
# def request_task():
#     url = urls.pop()
#     response = requests.get(url)
#     print(response)
#     time.sleep(1)
#
#
# def main():
#     for i in range(1, 282):
#         t = threading.Thread(target=request_task)
#         t.start()
#
# if __name__ == '__main__':
#     main()


# def t_main(url):
#     response = requests.get(url)
#     time.sleep(1)
#     return response
#
#
# def main():
#     # 上下文管理器 来管理线程池  每次取3个
#     with ThreadPoolExecutor(max_workers=3) as executor:
#         features = [executor.submit(t_main,
#                                     f"https://16.push2.eastmoney.com/api/qt/clist/get?pn={i}&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_={int(time.time() * 1000)}")
#                     for i in range(1, 10)]
#         for feature in as_completed(features):
#             print(f"Result: {feature.result()}")
#
# if __name__ == '__main__':
#     main()




num = 0


def t1_main():
    global num
    for i in range(1000000):

        num += 1

def t2_main():
    global num
    for i in range(1000000):
        num += 1


def main():
    t1 = threading.Thread(target=t1_main)
    t2 = threading.Thread(target=t2_main)
    t1.start()
    t2.start()
    # 等待t1  t2 执行完毕
    t1.join()
    t2.join()
    print(num)

if __name__ == '__main__':
    main()














